package webs;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.pojo.News;
import domain.ApplicationContext;
import domain.NewsFacade;

import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: winstars
 * Date: 2007-2-28
 * Time: 15:42:41
 * To change this template use File | Settings | File Templates.
 */
public class ShowACMinZust extends HttpServlet {
	
	private NewsFacade newsService;

    @Override
    protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        doPost(httpServletRequest,httpServletResponse);
    }

    @Override
    protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    	httpServletRequest.setCharacterEncoding("UTF-8");
    	
    	NewsFacade newsService = (NewsFacade)ApplicationContext.get("NewsService");
    	ArrayList<News> newsList = newsService.getAllNews();
    	HttpSession httpsession = httpServletRequest.getSession();    	
    	httpsession.setAttribute("newsList", newsList);
    	httpServletResponse.sendRedirect("acm_in_zust.jsp");
    }

    @Override
    public void destroy() {
        super.destroy();    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public void init() throws ServletException {
        super.init();    //To change body of overridden methods use File | Settings | File Templates.
    }

	public NewsFacade getNewsService() {
		return newsService;
	}

	public void setNewsService(NewsFacade newsService) {
		this.newsService = newsService;
	}
}
